﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Helpers;
using EuroManager.Domain.Simulator.World;

namespace EuroManager.Domain.Simulator
{
    [ContractClass(typeof(RandomizerContract))]
    public interface IRandomizer
    {
        Vector2D AutoBallKickVelocity(float minLength, float maxLength);

        float PlayerAIDecisionDelaySalt(float delay);

        bool ShouldPassBall(float chance);

        IPlayer PlayerToPassBallTo(IEnumerable<IPlayer> players, float[] chances);

        float PlayerReceivePassSpeed(float minSpeed, float maxSpeed);

        bool ShouldShoot(float chance);
    }

    [ContractClassFor(typeof(IRandomizer))]
    public abstract class RandomizerContract : IRandomizer
    {
        public Vector2D AutoBallKickVelocity(float minLength, float maxLength)
        {
            Contract.Requires(minLength.IsRational() && minLength >= 0);
            Contract.Requires(maxLength.IsRational() && maxLength >= 0);
            Contract.Requires(maxLength >= minLength);
            return Vector2D.Zero;
        }

        public float PlayerAIDecisionDelaySalt(float delay)
        {
            Contract.Requires(delay.IsRational());
            return 0;
        }

        public bool ShouldPassBall(float chance)
        {
            Contract.Requires(chance.IsRational() && chance >= 0 && chance <= 1);
            return false;
        }

        public IPlayer PlayerToPassBallTo(IEnumerable<IPlayer> players, float[] chances)
        {
            Contract.Requires(players != null && players.Any());
            Contract.Requires(chances != null && chances.Length == players.Count());
            return null;
        }

        public float PlayerReceivePassSpeed(float minSpeed, float maxSpeed)
        {
            Contract.Requires(minSpeed.IsRational() && minSpeed >= 0);
            Contract.Requires(maxSpeed.IsRational() && maxSpeed >= 0);
            Contract.Requires(maxSpeed >= minSpeed);
            return 0;
        }

        public bool ShouldShoot(float chance)
        {
            Contract.Requires(chance.IsRational() && chance >= 0 && chance <= 1);
            return false;
        }
    }
}
